package View;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;

import javax.swing.*;
import javax.swing.event.*;

import Controller.AddressBookController;
import Controller.NewContactListener;


/**
 * View to create  a contact
 * 
 */	

public class NewContactView extends JDialog {
	
	private NewContactView that = this ;
	private AddressBookController controller;
	private NewContactListener listener;
	
	
	public static final String FIRSTNAME = "First name: ";
	public static final String LASTNAME= "Last Name: ";
	public static final String GROUP = "Group: " ;
	public static final String HOMEADDRESS = "Home Address: ";
	public static final String COMPANYNAME = "Company Name: ";
	public static final String COMPANYADDRESS = "Company Address: ";
	public static final String PERSPHONE = "Personal Phone: ";
	public static final String PROPHONE = "Professional Phone: ";
	public static final String WEBSITE = "Web Site: ";
	public static final String EMAIL = "Email: ";
	public static final String BIRTHDATE = "Birthdate: ";
	public static final String IMAGE = "Image: ";
	public static final String DATE ="Date: ";
	public static final String OPEN ="Open";
	
	
	public static final String OK = "OK";
	public static final String CANCEL = "Cancel";
	public static final String NOTHING = "";
	
	JPanel p1,p2;
	JButton bOK,bCancel,bOpen;
	JTextField tfFirstName,tfLastName,tfGroup,tfHomeAddress,tfCompanyName,tfCompanyAddress,tfPersPhone,tfProPhone,tfWebSite,tfEmail,tfBirthDate;
	JLabel lFirstName,lLastName,lGroup,lHomeAddress,lCompanyName,lCompanyAddress,lPersPhone,lProPhone,lWebSite,lEmail,lBirthDate,lImage,lImageName;

	//Default Constructor
	public NewContactView (AddressBookController controller) {
		
		this.controller=controller;
		this.listener = new NewContactListener(that, controller);
		
		//p1 with all the textField and Labels
		p1 = new JPanel();
		p1.setLayout(new GridLayout(20,2));
		p1.add(lFirstName = new JLabel(FIRSTNAME,10));
		p1.add(tfFirstName = new JTextField(NOTHING,15));
		p1.add(lLastName = new JLabel(LASTNAME,10));
		p1.add(tfLastName = new JTextField(NOTHING,15));
		p1.add(lGroup = new JLabel(GROUP,10));
		p1.add(tfGroup = new JTextField(NOTHING,15));
		p1.add(lHomeAddress = new JLabel(HOMEADDRESS,10));
		p1.add(tfHomeAddress = new JTextField(NOTHING,15));
		p1.add(lCompanyName = new JLabel(COMPANYNAME,10));
		p1.add(tfCompanyName = new JTextField(NOTHING,15));
		p1.add(lCompanyAddress = new JLabel(COMPANYADDRESS,10));
		p1.add(tfCompanyAddress = new JTextField(NOTHING,15));
		p1.add(lPersPhone = new JLabel(PERSPHONE,10));
		p1.add(tfPersPhone = new JTextField(NOTHING,15));
		p1.add(lProPhone = new JLabel(PROPHONE,10));
		p1.add(tfProPhone = new JTextField(NOTHING,15));
		p1.add(lWebSite = new JLabel(WEBSITE,10));
		p1.add(tfWebSite = new JTextField(NOTHING,15));
		p1.add(lEmail = new JLabel(EMAIL,10));
		p1.add(tfEmail = new JTextField(NOTHING,15));
		p1.add(lBirthDate = new JLabel(BIRTHDATE,10));
		p1.add(tfBirthDate = new JTextField(NOTHING,15));
		p1.add(lImage = new JLabel(IMAGE,10));
		p1.add(bOpen = new JButton(OPEN));
		
		//p2 holds the buttons
		p2 = new JPanel();
		p2.setLayout(new FlowLayout());
		p2.add(bOK = new JButton (OK));
		p2.add(bCancel = new JButton (CANCEL));
		
		//Add panels to the frame
		getContentPane().add(p1, BorderLayout.NORTH);
		getContentPane().add(p2, BorderLayout.SOUTH);
		
		//Action Listeners
		bOK.addActionListener(listener);
		bCancel.addActionListener(listener);
		bOpen.addActionListener(listener);
		
		
		
	}
	
	
	public  AddressBookController getController() {
		return listener.getController();
	}
	
	//For tests
	
	/*public static void main (String [] args) {
		
		AddressBookController controller = new AddressBookController();
		
		NewContactView frame = new NewContactView(controller);
		frame.setTitle("New Contact");
		frame.setSize(500,600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		
	}
	*/
	
	public String getTfFirstName (){
		return tfFirstName.getText();
	}
	public String getTfLastName (){
		return tfLastName.getText();
	}
	public String getTfGroup (){
		return tfGroup.getText();
	}
	public void setTfGroup(String value){
		tfGroup.setText(value);
	}
	public String getTfHomeAddress (){
		return tfHomeAddress.getText();
	}
	public String getTfCompanyName (){
		return tfCompanyName.getText();
	}
	public String getTfCompanyAddress(){
		return tfCompanyAddress.getText();
	}
	public String getTfPersPhone (){
		return tfPersPhone.getText();
	}
	public String getTfProPhone(){
		return tfProPhone.getText();
	}
	public String getTfWebSite(){
		return tfWebSite.getText();
	}
	public String getTfEmail(){
		return tfEmail.getText();
	}
	public String getTfBirthDate(){
		return tfBirthDate.getText();
	}
	public String getImageName(){
		return lImageName.getText();
	}
	public void setImageName(String imageAddress){
		bOpen.setText(imageAddress);
	}
	

	
	
}
